package com.itheima.controller;

import com.itheima.common.PageBean;
import com.itheima.common.R;
import com.itheima.domain.pojo.TCheckItem;
import com.itheima.service.TCustomerSerevce;
import com.itheima.service.YCheckItemSeverl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 检查项
 * @CrossOrigin:是为了解决前端请求后端发生跨域
 */
@RestController
@RequestMapping("checkItem")
@CrossOrigin
@Api(tags = "检查项管理")
public class TCheckItemController {

    @Autowired
    private YCheckItemSeverl yCheckItemSeverl;

    @GetMapping("/pageQuery")
    @ApiOperation("带条件分页查询")
    public R selectAll(@RequestParam(defaultValue = "1") @ApiParam(name ="page" ,value = "第几页") Integer page, @RequestParam(defaultValue = "1") @ApiParam(name = "size",value = "一页的数据") Integer size,@ApiParam(name = "name" ,value = "姓名") String name) {
        PageBean pageBean = yCheckItemSeverl.selectAll(page, size, name);
        return R.ok(pageBean);
    }

    @PostMapping
    @ApiOperation("新增检查项")
    public R add(@RequestBody @ApiParam(name = "tCheckItem" ,value = "检查项数据") TCheckItem tCheckItem) {
        yCheckItemSeverl.add(tCheckItem);
        return R.ok();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询检查项")
    public R selectById(@PathVariable @ApiParam(name = "id",value = "检查项的id") Integer id) {
        TCheckItem tCheckItem = yCheckItemSeverl.selectById(id);
        return R.ok(tCheckItem);
    }

    @PutMapping
    @ApiOperation("修改检查项")
    public R update(@RequestBody TCheckItem tCheckItem) {
        yCheckItemSeverl.update(tCheckItem);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除检查项")
    public R delete(@PathVariable Integer id) {
        yCheckItemSeverl.delete(id);
        return R.ok();
    }
}

